#include "Scene/SceneGraph.h"

#include "Graphics/IRenderEngine.h"
#include "Graphics/IViewport.h"
#include "Camera/Camera.h"


namespace tyro
{
	namespace Scene
	{


		SceneGraph::SceneGraph( Engine::Engine* engine )
			:	engine(engine)
			,	renderEngine(engine->GetRenderEngine())
		{

		}

		SceneGraph::~SceneGraph()
		{

		}

		void SceneGraph::RenderScene( Camera::Camera* camera, Graphics::IViewport* viewport )
		{

			renderEngine->SetViewport(viewport);

			// Clear the colour, depth and stencil buffers
			renderEngine->ClearBuffers( viewport->GetClearBuffers(), viewport->GetBackColour(), viewport->GetDepthClear() );


			renderEngine->BeginFrame();

			renderEngine->SetProjectionMatrix(camera->GetProjectionMatrix());

			renderEngine->SetModelViewMatrix();

			renderEngine->DrawCube();

			renderEngine->EndFrame();
			
		}

		Camera::Camera* SceneGraph::CreateCamera( const String& name )
		{
			// Create the camera 
			Camera::Camera* camera = new Camera::Camera(name, engine);

			// Add camera to the scene graph
			sceneCameras.insert(Camera::CameraMap::value_type(name, camera));

			// Return the camera
			return camera;
		}



	}
}